# -*- coding: utf-8 -*-
'''
Created on 30-09-2012

@author: LONG HOANG GIANG
'''


import mechanize
import urllib
import simplejson as json

cookie = "ASP.NET_SessionId=x0sqdeawnbmt5t55jhhns5qi; userName=0137218"

data = json.dumps({"isKhoa":False,"maKhoaLop":"B18MX","dk":""})

def load(cookieStr):
    
    url = "http://daotao.nuce.edu.vn/ajaxpro/EduSoft.Web.UC.DangKyMonHoc,EduSoft.Web.ashx"
    refererUrl = "http://daotao.nuce.edu.vn/Default.aspx?page=dkmonhoc"
    opener = mechanize.build_opener(mechanize.HTTPRedirectHandler)
    opener.addheaders = [("User-Agent", "Mozilla/5.0 (Windows NT 6.2; rv:18.0) Gecko/20100101 Firefox/18.0"), 
                         ("Referer", refererUrl), 
                         ("X-AjaxPro-Method", "LocTheoMaKhoa"),
                         ("Cookie", cookieStr)]
    mechanize.install_opener(opener)
    fd = mechanize.urlopen(url, data)
    print fd.info()
    print fd.read()
    
load(cookie)